package cn.jhc;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

@WebServlet("/admin/list.do")
public class ListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Item> items = new ArrayList<>();
        try {
            items = new DaoRu().findAllItems();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        Gson gson = new Gson();
        String itemsList = gson.toJson(items);
        resp.setContentType("application/json");
        resp.getWriter().print(itemsList);
        
    }
    
}
